home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / iflib / bread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-22  |  974 b   |  71 lines

  1. #include <stdio.h>
  2. #include "bread.h"
  3. #include "config.h"
  4.  
  5. /* read short (16bit) integer in "standart" byte order */
  6. int iread(fp)
  7. FILE *fp;
  8. {
  9.     unsigned char lo,hi;
  10.  
  11.     fread(&lo,1,1,fp);
  12.     fread(&hi,1,1,fp);
  13.     return (hi<<8) | lo;
  14. }
  15.  
  16. /* read long (32bit) integer in "standart" byte order */
  17. long lread(fp)
  18. FILE *fp;
  19. {
  20.     int c;
  21.     unsigned char buf;
  22.     long ret=0L;
  23.  
  24.     for (c=0;c<32;c+=8)
  25.     {
  26.         fread(&buf,1,1,fp);
  27.         ret |= ((unsigned long)buf << c);
  28.     }
  29.     return ret;
  30. }
  31.  
  32. static int at_zero=0;
  33.  
  34. char *aread(s,count,fp)
  35. char *s;
  36. int count;
  37. FILE *fp;
  38. {
  39.     int i,c,next;
  40.  
  41.     if (feof(fp)) return(NULL);
  42.     if (s == NULL) return NULL;
  43.     if (at_zero)
  44.     {
  45.         at_zero=0;
  46.         return NULL;
  47.     }
  48.  
  49.     for (i=0,next=1;(i<count-1) && next;)
  50.     switch (c=getc(fp))
  51.     {
  52.     case '\n':    break;
  53.     case '\r':    s[i]='\n';
  54.             s[i+1]='\0';
  55.             next=0;
  56.             break;
  57.     case 0x8d:    s[i]=' ';
  58.             i++;
  59.             break;
  60.     case '\0':    at_zero=1;
  61.             s[i]='\0';
  62.             next=0;
  63.             break;
  64.     default:    s[i]=intab[c];
  65.             i++;
  66.             break;
  67.     }
  68.     s[i+1]='\0';
  69.     return s;
  70. }
  71.